package com.example.cloudcustomer.fallback;

import com.example.cloudcustomer.client.CustomerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Project: spring-cloud
 * @Package: com.example.cloudcustomer.fallback
 * @Author: 壹陸捌
 * @Time: 2025 - 08 - 05 10 : 57
 * @Description: 断路器
 */
@Component
public class CustomerClientFallbackFactory implements FallbackFactory<CustomerClient> {

    private static final Logger logger = LoggerFactory.getLogger(CustomerClientFallbackFactory.class);


    @Override
    public CustomerClient create(Throwable cause) {
        return new CustomerClient() {
            @Override
            public String selectProvide(String mark) {
                logger.warn("Feign 调用失败，触发熔断，异常信息: {}", cause.getMessage());
                return "断路器（Resilience4j）已开启服务保护";
            }
        };
    }
}
